package com.hisense.hiioc.hismartplate.robot.factory;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;

import java.util.concurrent.TimeUnit;

/**
 * @Auther:biexiande@hisense.com
 * @date:2018/12/17 16:31
 * @des
 */
public enum CacheFactory {
    INSTANCE;
    private  LoadingCache<String,String> loadingCache =null;
    private  LoadingCache<String,Long> clickEventCache =null;
    CacheFactory() {
        loadingCache= CacheBuilder.newBuilder()
                /*设置缓存容器的初始容量大小为100*/
                .initialCapacity(100)
                /*设置缓存容器的最大容量大小为1000*/
                .maximumSize(1000)
                /*设置记录缓存命中率*/
                .recordStats()
                /*设置并发级别为50*/
                .concurrencyLevel(50)
                /*设置过期时间为2分钟*/
                .expireAfterAccess(2, TimeUnit.MINUTES).build(new CacheLoader<String, String>() {
                    @Override
                    public String load(String key) throws Exception {
                        return "";
                    }
                });

        clickEventCache= CacheBuilder.newBuilder()
                .initialCapacity(200)
                .maximumSize(5000)
                .recordStats()
                .concurrencyLevel(80)
                .expireAfterAccess(10, TimeUnit.MINUTES).build(new CacheLoader<String, Long>() {
                    @Override
                    public Long load(String key) throws Exception {
                        return null;
                    }
                });
    }

    public LoadingCache getCache() {
        return loadingCache;
    }

    public LoadingCache clickEventCache() {
        return clickEventCache;
    }

}